﻿(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return decodeURIComponent(r[2]);
        return null;
    }
})(jQuery);


/*每日彩JS-SDK*/
var mrc = function (_url, _receive, _data) {
    this.url = _url;
    this.data = _data || {};

    /*接收ajax的数据*/
    this.receive = _receive || function (json) {
    };

    /*发送请求之前的处理*/
    this.beforeSend = function () {
        var index = this.url.indexOf("?");
        this.url = service.getRealUrl(this.url) + this.url.substr(index);
    };

    /*发送消息*/
    this.send = function () {
        this.data.r = Math.random();
        $.ajax({
            type: "get",
            url: this.url,
            data: this.data,
            dataType: "json",
            beforeSend: this.beforeSend,
            success: this.receive
        });
    }
};

/*
      *{captions:"",monitors:""} ……
      *主显示面板切换器
      */
function switchLight(options) {
    this.panel = [];
    for (var i = 0; i < arguments.length; i++) {
        this.panel.push(arguments[i]);
    }

    this.action = function (_this) {
        var index = this.getIndex(_this.id);
        this.styleSwitch(index);
        this.panelSwitch(index);
    };

    /*
    *获取jquery的选择Id
    */
    this.Jid = function (id) {
        return "#" + id;
    };

    /*
    *查找当前标题的索引
    */
    this.getIndex = function (id) {
        for (var i in this.panel) {
            if (this.panel[i].caption == id) {
                return i;
            }
        }
        return -1;
    };

    /*
    *主面板切换
    */
    this.panelSwitch = function (index) {
        var jDom = null;
        for (var i in this.panel) {
            jDom = $(this.Jid(this.panel[i].monitors));
            if (i == index) {
                jDom.show();
            }
            else {
                jDom.hide();
            }
        }
    };

    /*
    *标题样式切换
    */
    this.styleSwitch = function (index) {
        var jDom = null;
        for (var i in this.panel) {
            jDom = $(this.Jid(this.panel[i].caption));
            jDom.removeClass();
            if (i == index) {
                jDom.addClass("turnOn");
            }
            else {
                jDom.addClass("turnOff");
            }
        }
    };
}

/*绘制中奖球码*/
function drawBall(number, color) {
    return "<span class='ball   " + color + "'>" + number + "</span>";
}